package presentation.web;

import java.io.UnsupportedEncodingException ;
import java.net.URLDecoder ;

import jaxcent.HtmlPara ;
import jaxcent.Jaxception ;

/**
 * page for errors
 *
 */
public class ErrorPage extends MainPage
{
	/** place for error messages **/
	private HtmlPara errorsPara;

	private HtmlPara homeLink;

	/**
	 * Instantiates an error page
	 */
	public ErrorPage()
	{
		super() ;
		try
		{
			this.homeLink = new HtmlPara(this,"home");
			String page = MainPage.pageLinks.get(MainPage.HOME_PAGE) ;
			String home = MainPage.makeLink(page, "press here to go back to home page") ;
			String error = this.getPageParams().get("error") ;
			if (error == null)
			{
				error = "none" ;
			}
			error = this.fixHtmlString(error) ;
			this.setError(error,home);
		}
		catch (Exception e)
		{
			//ignore
		}
	}

	private String fixHtmlString(final String str)
	{
		try
		{
			return URLDecoder.decode(str, "UTF-8") ;
		}
		catch (UnsupportedEncodingException e)
		{
			// ignore, cannot throw exceptions...
			return "there was a problem in presenting this page. the original error string is: <br>" + str ;
		}
	}



	private void setError(final String error, final String home)
	{
		try
		{
			this.errorsPara = new HtmlPara(this,"errorField");
			this.homeLink.setInnerHTML(home);
			this.errorsPara.setInnerHTML(error) ;
		}
		catch (Jaxception e)
		{
			// ignored
		}
	}


}
